package ypmits.cms {
	import ypmits.cms.view.windows.Back;
	import ypmits.cms.view.windows.Login;
	import ypmits.components.buttons.CloseButton;
	import ypmits.setup.EasySetup;

	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;

	/**
	 * @author Dave Lenz
	 */
	public class CMS extends Sprite implements ICMS {

		private var back : Back;
		private var login : Login;
		//		private var sectiondetail : SectionDetail;
		//		private var sectionchooser : SectionChooser;
		private var closebutton : CloseButton;

		
		public function CMS() {
			EasySetup.instance.addEventListener( Event.RESIZE, resizeHandler );

			build( );
		}

		
		private function build() : void {
			login = Login.instance;
			closebutton = new CloseButton( );
			closebutton.addEventListener( MouseEvent.CLICK, closeHandler );
			//			sectionchooser = SectionChooser.instance;
			//			sectiondetail = SectionDetail.instance;
			addChild( back );
			addChild( login );
			addChild( closebutton );
			//			addChild( sectionchooser );
			//			addChild( sectiondetail );
			blendMode = BlendMode.LAYER;
			visible = false;
			alpha = 0;
			filters = [ new DropShadowFilter( 4, 45, 0, .4, 7, 7, 1, 3 ) ];
			
			resizeHandler( );
		}

		
		private function closeHandler( e : MouseEvent ) : void {
			hide( );
		}

		
		public function show() : void {
			visible = true;
		}

		
		private function hideDone() : void {
			enable( );
			back.resize( 300, 500 );
		}

		
		public function hide( ) : void {
			disable( );
			visible = false;
		}

		
		private function enable() : void {
			mouseEnabled = mouseChildren = true;
		}

		
		private function disable() : void {
			mouseEnabled = mouseChildren = false;
		}

		
		private function resizeHandler( event : Event = null ) : void {
			if( back && back.width ) {
				if( closebutton ) {
					closebutton.x = ( back.width * .5 );
					closebutton.y = -( back.height * .5 );
				}
			}
			x = EasySetup.instance.stage.stageWidth * .5;
			y = EasySetup.instance.stage.stageHeight * .5;
		}
	}
}
